import { configure, makeAutoObservable } from 'mobx';
import { TenantEntity } from '@/entities/TenantEntity';
import { LandlordEntity } from '@/entities/LandlordEntity';
import { LeaseEntity } from '@/entities/LeaseEntity';

configure({
  enforceActions: 'always'
});

class UserStore {

  constructor() {
    makeAutoObservable(this, {}, {autoBind: true});
  }

  /**
   * 用户信息
   */
  user: any | TenantEntity.ITenant | LandlordEntity.ILandlord;

  /**
   * 当前房东信息
   */
  currentLandlord: any | LandlordEntity.ILandlord;

  /**
   * 已经租赁该房东房屋的租客信息
   */
  releaseTenant: any | LeaseEntity.IExistLease = [];

  /**
   * 设置用户信息
   * @param user 用户信息
   */
  setUser(user: TenantEntity.ITenant | LandlordEntity.ILandlord) {
    this.user = user;
  }

  /**
   * 清除用户信息
   */
  clearUser() {
    this.user = null;
  }

  /**
   * 设置当前房东信息
   */
  setCurrentLandlord(landlord?: LandlordEntity.ILandlord) {
    this.currentLandlord = landlord;
  }

  /**
   * 设置已经租赁该房东房屋的租客信息
   */
  setReleaseTenant(tenant: TenantEntity.ITenant[]) {
    this.releaseTenant = tenant;
  }

  /**
   * 清除已经租赁该房东房屋的租客信息
   */
  clearReleaseTenant() {
    this.releaseTenant = [];
  }
}

const userStore = new UserStore();
export default userStore;